const dom = document.querySelector('.headers');

function domToJSON(dom) {
  let obj = {};
  obj.name = dom.tagName;
  obj.children = [];
  dom.childNodes.forEach(child => { obj.children.push(domToJSON(child)) });
}

domToJSON(dom);